<template>
    <el-card shadow="never">
        <yun-table
                :columns="columns"
                toolbar="refresh,add,edit,del,more"
                :add-form="{height:580}"
                :edit-form="{height:580}"
                :auth="{
                    add:{:$auth->check('app\\admin\\controller\\delivery\\channel\\Coupon','add')},
                    edit:{:$auth->check('app\\admin\\controller\\delivery\\channel\\Coupon','edit')},
                    del:{:$auth->check('app\\admin\\controller\\delivery\\channel\\Coupon','del')},
                    multi:{:$auth->check('app\\admin\\controller\\delivery\\channel\\Coupon','multi')},
                }"
                :extend="extend">
        </yun-table>
    </el-card>
</template>
<script>
import table from "@components/Table.js";
export default{
    components:{
        'YunTable':table
    },
    data:{
        extend:{
            index_url: 'delivery/channel-coupon/index',
            add_url: 'delivery/channel-coupon/add',
            edit_url: 'delivery/channel-coupon/edit',
            del_url: 'delivery/channel-coupon/del',
            multi_url: 'delivery/channel-coupon/multi',
        },
        columns:[
            {checkbox: true},
            {field:"title",title:"名称",operate:"like"},
            {field:"type",title:"类型",operate:{form:"select",filter:"="},searchList:Yunqi.data.couponTypeList,formatter:Yunqi.formatter.tag},
            {field:"description",title:"使用场景",operate:false,visible:false},
            {field:"discount",title:"使用规则",width:180,operate:false,formatter: function (data,row){
                if(row.type == 'discount'){
                    return row.discount + '折';
                }else if(row.type == 'goods'){
                    return '凭券购买指定商品'+row.goods_number+'件';
                }else if(row.type == 'card'){
                    return '面值'+row.balance+'元';
                }else if(row.type == 'cash'){
                    return row.cash + '元';
                }else if(row.type == 'full_minus'){
                    let html=Yunqi.formatter.html;
                    let full_minus=JSON.parse(row.full_minus);
                    html.value='<div style="text-align: center">';
                    for(let  i in full_minus){
                        html.value+='满'+i+'减'+full_minus[i]+'<br>';
                    }
                    html.value+='</div>';
                    return html;
                }
            }},
            {field:"goods_id",title:"支持商品",width:150,formatter: function (data){
                if(!data){
                    let tag=Yunqi.formatter.tag;
                    tag.type='danger';
                    tag.value='未设置';
                    return tag;
                }
                let tags=Yunqi.formatter.tags;
                tags.value=[];
                let goods_ids=data.split(',');
                for(let k in Yunqi.data.goods){
                    for(let i=0;i<goods_ids.length;i++){
                        if(goods_ids[i]==k){
                            tags.value.push(Yunqi.data.goods[k]);
                        }
                    }
                }
                return tags;
            }},
            {field: 'expire', title: '有效期',operate:false,formatter:function (data) {
                if(!data)return '不限制';
                return data+'天';
            }},
            {field: 'total', title: '发放总数',operate:false,formatter:function (data) {
                if(!data)return '不限制';
                return data+'张';
            }},
            {field: 'send', title: '已经发放',operate:false,formatter:function (data) {
                return data+'张';
            }},
            {field: 'take', title: '已经核销',operate:false,formatter:function (data) {
                return data+'次';
            }},
            {field:"limit_day",title:"使用数量限制",operate:false,formatter: function (data,row){
                if(row.limit_day && row.limit_num){
                    return '每'+row.limit_day+'天限制使用'+row.limit_num+'张';
                }
                return '不限制';
            }},
            {field:"use_limit_type",title:"使用日期限制",operate:false,formatter: function (data,row){
                if(!data)return '不限制';
                if(data=='date'){
                    let date=row.use_limit_date.split(',');
                    return date[0].slice(0,10)+' 至 '+date[1].slice(0,10);
                }
                if(data=='week'){
                    let week=['星期日','星期一','星期二','星期三','星期四','星期五','星期六'];
                    let use_limit_week=row.use_limit_week.split(',');
                    let tags=Yunqi.formatter.tags;
                    tags.value=[];
                    for(let i=0;i<use_limit_week.length;i++){
                        tags.value.push(week[use_limit_week[i]]);
                    }
                    return tags;
                }
            }},
            {field:"status",width:100,title:"状态",operate:"select",searchList:{normal:"正常",hidden:"隐藏"},formatter:Yunqi.formatter.switch},
            {
                field: 'operate',
                title: __('操作'),
                fiexd:"right",
                width:130,
                action:{
                    edit:true,
                    del:true,
                }
            }
        ]
    },
    methods: {
    }
}
</script>
<style>
</style>